<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //obj深拷贝
        // var obj1 = {name : 'lisi' ,age :'24'}
        // var obj2 = {}
        // //遍历obj1的key
        // for(var k in obj1){
        //     obj2[k] = obj1[k]
        // }
        // console.log( obj2[k])
        // console.log(obj1[k])
        // console.log(obj2===obj1) //false 引用地址不同
        // console.log(obj2[k] === obj1[k]) //true  key相同

        //封装对象拷贝
        function deepCopy(obj){
            var result = {}
            for(var k in obj){
                result[k] = obj[k]
        }
            return result;
        }
        var obj1 = {name : 'lisi' ,age :'24'}
        var obj2 =deepCopy(obj1)
      
        console.log( obj2 )
    </script>
   
</body>
</html>